﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.CacheService.CacheProvider.LocalCache;
using A2DFramework.CacheService.Configuration;
using ServiceStack.Redis;

namespace A2DFramework.CacheService.CacheProvider
{
    class RedisCacheProvider : ICacheExecutor
    {
        private CacheServerInfo configInfo;
        protected RedisClient redis=null;
        public RedisCacheProvider(CacheServerInfo configInfo)
        {
            this.configInfo = configInfo;
            redis = new RedisClient(configInfo.ServerAddress, configInfo.ServerPort);
        }
        public void Put(string key, object value, CacheExpireType expireType, double increment)
        {
            redis.Add(key, value, TimeHelper.CalculateExpirationDateTime(expireType, increment));
        }

        public object Get(string key)
        {
            return redis.GetValue(key);
        }

        public void Remove(string key)
        {
            redis.Remove(key);
        }
    }
}
